<template>
  <div class="module-wrapper">
    <!-- 中间预览 -->
    <div class="center-panel">
      <CustomerServicePreview :config="localConfig" />
    </div>
    <!-- 右侧配置 -->
    <div class="right-panel">
      <CustomerServiceConfig v-model="localConfig" />
    </div>
  </div>
</template>

<script>
  import CustomerServicePreview from '../components/previews/CustomerServicePreview.vue';
  import CustomerServiceConfig from '../components/configs/CustomerServiceConfig.vue';

  export default {
    name: "CustomerServiceModule",
    components: {
      CustomerServicePreview,
      CustomerServiceConfig
    },
    props: {
      config: {
        type: Object, // 客服设置的数据结构是对象
        default: () => ({})
      }
    },
    data() {
      return {
        localConfig: {} // 本地副本是对象
      };
    },
    watch: {
      config: {
        handler(newValue) {
          this.localConfig = JSON.parse(JSON.stringify(newValue));
        },
        immediate: true,
        deep: true
      },
      localConfig: {
        handler(newValue) {
          this.$emit('update:config', newValue);
        },
        deep: true
      }
    },
    // computed: {
    //   configData: {
    //     get() {
    //       return this.config;
    //     },
    //     set(newValue) {
    //       this.$emit('update:config', newValue);
    //     }
    //   }
    // }
  }
</script>

<style lang="scss" scoped>
  /* 模块主容器，确保占满父级空间 */
  .module-wrapper {
    display: flex;
    width: 100%;
    height: 100%;
  }

  /* 中间预览面板 */
  .center-panel {
    flex: 1;
    background: #f7f8fa;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    overflow-y: auto;
  }

  /* 右侧配置面板 */
  .right-panel {
    width: 450px;
    background: #fff;
    border-left: 1px solid #e8e8e8;
    padding: 20px;
    overflow-y: auto;
    flex-shrink: 0;
    padding-bottom: 80px;
    /* 防止被压缩 */
  }


  /* 手机模拟器外壳 */
  .mobile-preview-wrapper {
    width: 375px;
    min-height: 667px;
    background-color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-radius: 20px;
    border: 8px solid #333;
    overflow: hidden;
    /* 保证内部内容不会超出圆角 */
    display: flex;
    flex-direction: column;
  }

  /* 手机模拟器头部 */
  .mobile-header {
    height: 44px;
    line-height: 44px;
    text-align: center;
    font-weight: bold;
    border-bottom: 1px solid #eee;
    background-color: #fff;
    flex-shrink: 0;
    /* 防止头部被压缩 */
  }

  /* 手机模拟器内容区域 */
  .mobile-body {
    flex: 1;
    overflow-y: auto;
    background: #f7f8fa;
    /* 内容区域背景色 */
  }

  /* 可拖拽组件的包装器 */
  .preview-component-wrapper {
    position: relative;

    /* 鼠标悬浮时，显示覆盖层 */
    &:hover .preview-overlay {
      border-color: #409EFF;
    }

    /* 鼠标悬浮时，显示拖拽手柄和操作按钮 */
    &:hover .preview-drag-handle,
    &:hover .preview-actions {
      display: block;
    }
  }

  /* 预览组件的覆盖层，用于显示边框和接收鼠标事件 */
  .preview-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px dashed transparent;
    transition: border-color 0.2s;
    /* 允许下层组件的鼠标事件（如点击），但拖拽手柄除外 */
    pointer-events: none;
  }

  /* 拖拽手柄 */
  .preview-drag-handle {
    position: absolute;
    top: 0;
    left: 0;
    background: #409EFF;
    color: white;
    padding: 2px 8px;
    font-size: 12px;
    display: none;
    border-bottom-right-radius: 4px;
    cursor: move;
    /* 允许手柄接收鼠标事件 */
    pointer-events: all;
  }

  /* 操作按钮区域 (例如删除按钮) */
  .preview-actions {
    position: absolute;
    top: 0;
    right: 0;
    display: none;
    /* 允许按钮接收鼠标事件 */
    pointer-events: all;
    padding: 5px;
  }

  .config-component-wrapper {
    margin-bottom: 20px;
  }
</style>
